home *** CD-ROM | disk | FTP | other *** search
- Path: news.luc.edu!user
- From: VArase@varase.it.luc.edu (Verne Arase)
- Newsgroups: comp.lang.c
- Subject: Re: Why does my program do this?
- Date: Mon, 01 Apr 1996 16:16:50 -0600
- Organization: LUMC
- Message-ID: <AD85B1F29668E2CE7@mcdiala11.it.luc.edu>
- References: <4jnln2$95j@dfw-ixnews3.ix.netcom.com>
- NNTP-Posting-Host: 147.126.240.111
-
- In article <4jnln2$95j@dfw-ixnews3.ix.netcom.com>,
- ishky@ix.netcom.com(Andrew Heiz ) wrote:
-
- > for (i=0; i <= students-1; i=i+1)
-
- Might I suggest:
-
- for (i=0; i<students; i++)
-
- >char scores[STUDENT][5];
- > ...
- > for (i=0; i <= students-1; i=i+1)
- > {
- > for (j=0; j <= tests-1; j=j+1)
- > {
- > gets(&scores[i][j];
- > }
- > }
-
- I believe what you really want is to storage your score values in an
- arithmentic type (like short). Alternately, you'll want a three dimensional
- character matrix, as there is no intrinsic string type in C and you must
- use a character vector instead. Therefore, scores (in character form) would
- look something like the following:
-
- char scores[MAXSTUDENTS][MAXGRADES][MAXLENGTH+1]
-
- > for (i=0; i <= students-1; i=i+1)
- > {
- > printf("Scores for student %d",i+1);
- > for (j=0; j <= tests-1; j=j+1)
- > {
- > printf("\tGrade %d: %s",j+1,scores[i][j]);
- > }
- > }
-
- The %s is directing printf to print a string. In C, a string is a character
- vector (or pointer) with a run of characters terminated by a NUL ('\0').
-
- ---
- The above are my own opinions, and not those of my employer.
-